package com.biz.primus.ms.homepage.dataprovider;

import com.biz.primus.base.vo.commodity.ProductSimpleListItemVo;
import com.biz.primus.common.utils.JsonUtils;
import com.biz.primus.homepage.vo.CoverTemplateData;
import com.biz.primus.homepage.vo.MethodExecutorMethodParam;
import com.biz.primus.ms.base.service.AbstractBaseService;
import com.biz.primus.ms.homepage.helper.BeanDiscoverer;
import com.biz.primus.ms.homepage.helper.MethodExecutable;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;

/**
 * @author defei
 * @date 2/11/17
 * 单页促销数据提供者,返回商品单页促销banner 以及商品基本信息,库存 价格等信息
 */
@Slf4j
@Service
public class ProductPagePromotionService extends AbstractBaseService implements MethodExecutable {


    @PostConstruct
    public void setup() {

        BeanDiscoverer.put(this);
    }

    @Override
    public String getIdentity() {

        return "ProductPagePromotionDataProvider";
    }

    @Override
    public String getDescription() {

        return "返回首页单页促销数据";
    }

    @Override
    public CoverTemplateData execute(MethodExecutorMethodParam param) {

        CoverTemplateData respVo = new CoverTemplateData();
        List<CoverTemplateData> promotionDatas = newArrayList();
        if (param.getIdentity() == null) {
            log.error("单页促销ID为空!");
        }
        CoverTemplateData promotionLogo = new CoverTemplateData();
//        promotionLogo.setImgUrl(activityById.getActivityLogo());
//        promotionLogo.setLink(activityById.getUrl());
        promotionDatas.add(promotionLogo);
        List<ProductSimpleListItemVo> promotionResp = Lists.newArrayList();
        for (ProductSimpleListItemVo productListItemVo : promotionResp) {
            CoverTemplateData tmp = new CoverTemplateData();
            tmp.setId(productListItemVo.getProductCode());
            tmp.setExtraData(JsonUtils.obj2Json(productListItemVo));
            promotionDatas.add(tmp);
        }
        respVo.setElements(promotionDatas);
        return respVo;
    }

}
